package com.example.stream.demostream.service.impl;

import com.example.stream.demostream.entity.vo.CredentialVo;
import com.example.stream.demostream.service.ILoginService;
import com.zhe.shiro.component.JWTCreator;
import com.zhe.shiro.component.OAuth2Realm;
import com.zhe.shiro.domain.OAuth2Token;
import com.zhe.shiro.domain.TokenDto;
import com.zhe.shiro.service.PasswordHashFactory;
import com.zhe.web.entity.UserContextInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 手机密码登录
 * @author zhonghuaen
 * @create 2021-08-10
 */
@Service
public class CellphonePasswordLoginServiceImpl implements ILoginService {

    @Autowired
    private PasswordHashFactory passwordHashFactory;

    @Autowired
    private JWTCreator jwtCreator;

    /**
     * jwt方案
     * @param vo
     * @return
     */
    @Override
    public TokenDto login(CredentialVo vo) {
        // 生成token
        UserContextInfo contextInfo = UserContextInfo.builder()
                .id(5l).bid("2222")
                .username("testUserName").nickname("testNickName")
                .tenantCode("sys-admin").build();
        TokenDto token = jwtCreator.createTokenDto("2222", contextInfo);
        // token保存到redis
//        tokenSessionService.saveToken(sysManager.getBid(), ClientTypeEnum.PC, token);
        return token;
    }
}
